package bTree.LeetCode;

public class 外观数列 {
    public String countAndSay(int n) {
        String s = "1";
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < n; i++) {
            char point = s.charAt(0);
            int num = 1;
            for (int j = 1; j < s.length(); j++) {
                if (s.charAt(j) == point) {
                    num++;
                } else {
                    sb.append(String.valueOf(num) + point);
                    point = s.charAt(j);
                    num = 1;
                }
            }
            sb.append(String.valueOf(num) + point);
            s = sb.toString();
            sb = new StringBuilder();
        }
        return s;
    }
}